# Maintainer: Noel Kuntze <noel.kuntze@contauro.com>
pkgname=grommunio-sync
pkgdesc="Exchange ActiveSync interface for grommunio"
pkgver=2.0_git20240226
pkgrel=0
arch="noarch !riscv64"
url="http://www.kopano.com/"
license="AGPL-3.0-only"
options="!check" # No test suite
_php=php83
install="$pkgname.pre-install"
depends="grommunio-gromox
	grommunio-mapi-header-php
	$_php
	$_php-curl
	$_php-gettext
	$_php-iconv
	$_php-json
	$_php-mbstring
	$_php-openssl
	$_php-pecl-redis
	$_php-pdo_sqlite
	$_php-posix
	$_php-session
	$_php-simplexml
	$_php-soap"

_commithash=316257884382020bebfb4e3a2853cb560f3b208b

source="$pkgname-$pkgver.tar.gz::https://github.com/grommunio/grommunio-sync/archive/$_commithash.tar.gz"

builddir="$srcdir/grommunio-sync-$_commithash/"

build() {
	:
}

package() {
	# webapp
	install -dm755 "$pkgdir/usr/share/webapps/$pkgname/"
	cp -rp -- * "$pkgdir/usr/share/webapps/$pkgname/"

	# license
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

	# nginx conf
	sed -i "s@/var/log/grommunio/@/var/log/nginx/@" build/grommunio-sync.conf
	install -Dpm644 build/grommunio-sync.conf "$pkgdir/usr/share/grommunio-common/nginx/locations.d/grommunio-sync.conf"
	install -Dpm644 build/grommunio-sync-upstream.conf "$pkgdir/usr/share/grommunio-common/nginx/upstreams.d/grommunio-sync.conf"

	# php-fpm
	install -Dpm644 build/pool-grommunio-sync.conf "$pkgdir/etc/$_php/php-fpm.d/pool-grommunio-sync.conf"

	# logrotate
	install -Dm644 build/grommunio-sync.lr "$pkgdir/etc/logrotate.d/grommunio-sync"

	# web config
	install -Dm644 config.php "$pkgdir/etc/grommunio-sync/config.php"
	ln -sf "/etc/grommunio-sync/config.php" "$pkgdir/usr/share/webapps/grommunio-sync/config.php"

	# remove unnecessary files
	rm -rf "$pkgdir/usr/share/webapps/grommunio-sync/build"
	rm -f "$pkgdir/usr/share/webapps/grommunio-sync/LICENSE"

}

sha512sums="
6df33c39e114c5439548d6c465a57d0b2885acac77349cde7de7f3a0a6a3fb339747f62b77c46f25300a60ffafa1be690ebaeff5c6625e11aa9a51fba2f7d67a  grommunio-sync-2.0_git20240226.tar.gz
"
